package com.pension.org.controller;
import com.pension.org.entity.UserInfo;
import com.pension.org.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
public class LoginController {
    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping("/golog")
    public ModelAndView log(UserInfo user, Model model) {
        UserInfo u = userInfoService.findOne(user);
        model.addAttribute("user", u);
        ModelAndView mav = new ModelAndView();
        if (u != null) {
            mav.setViewName("success");
        } else{
            mav.setViewName("logno");
        }
            return mav;
    }
//    a标签里面有herf 跳转方法返回注册页面
    @RequestMapping("/zc")
    public ModelAndView log1() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("reg");
        return mav;
    }

    @RequestMapping("/goreg")
    public ModelAndView reg(UserInfo user) {
        UserInfo u = userInfoService.checkReg(user.getUsrLogin());
        ModelAndView mav = new ModelAndView();
        if (u == null) {
            userInfoService.addOne(user);
            mav.setViewName("regok");

        }else {
            mav.setViewName("regno");
        }
        return mav;
    }
//    返回主页
    @RequestMapping("/zy")
    public ModelAndView log2() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("log");
        return mav;
    }
}
